package states;

import game.Map;
import geom.Dimension2i;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;

import various_tmp.Direction;
import various_tmp.Game;

public class GameState extends State
{

  public static Map map;
  public static int viewWidth = Game.getInstance().getResolution().getWidth() / 2;
  public static int viewHeight = Game.getInstance().getResolution().getHeight() / 2;
  public static float mapX = 0, mapY = 0;
  public static Direction map_direction;

  @Override
  public int getID()
  {
    return Game.GAME_STATE;
  }

  @Override
  public void init(GameContainer arg0, StateBasedGame arg1)
      throws SlickException
  {
    map = new Map("data/level0001.tmx", new Dimension2i(viewWidth, viewHeight));
    map_direction = Direction.NONE;
  }

 

  @Override
  public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
      throws SlickException
  {

    g.scale(2f, 2f);
    
    map.draw((int)mapX, (int)mapY, g);
    g.setColor(Color.red);
  
    g.resetTransform();

    g.fillRect(mapX, mapY, 10.f, 10.f);



  }

  @Override
  public void update(GameContainer arg0, StateBasedGame arg1, int delta)
      throws SlickException
  {
    switch(map_direction)
    {
    case UP :
      mapY -= delta;
      break;
    case DOWN :
      mapY += delta;
      break;
    case LEFT :
      mapX -= delta;
      break;
    case RIGHT :
      mapX += delta;
      break;
    }
  }
  
  @Override
  public void keyPressed(int key, char c) {
     switch(key){
      case Input.KEY_DOWN :
        map_direction = Direction.DOWN;
        break;
      case Input.KEY_UP : 
        map_direction = Direction.UP;
        break;
      case Input.KEY_LEFT :
        map_direction = Direction.LEFT;
        break;
      case Input.KEY_RIGHT :
        map_direction = Direction.RIGHT;
        break;
      }
  }
  
  @Override
  public void keyReleased(int key, char c) {
     switch(key){
      case Input.KEY_DOWN :
        map_direction = Direction.NONE;
        break;
      case Input.KEY_UP : 
        map_direction = Direction.NONE;
        break;
      case Input.KEY_LEFT :
        map_direction = Direction.NONE;
        break;
      case Input.KEY_RIGHT : 
        map_direction = Direction.NONE;
        break;
      }
  }

}
